<template>
	<view class="container">
		<form @submit="submitForm" class="form">
			<view class="formBox">
				<page-head title="form"></page-head>
				<view class="uni-padding-wrap uni-common-mt">
					<form @submit="formSubmit" @reset="formReset">
						<!-- 检测时间 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_jcTime }}:</text>
							<view class="formB">
								<picker mode="date" :value="time" :start="startDate" :end="endDate"
									@change="bindTimeChange">
									<view class="uni-input">{{time}}</view>
								</picker>
							</view>
						</view>
						<!-- 体温 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_bodyTemperature }}:</text>
							<view class="formB">
								<input type="text" v-model="info.bodyTemperature"
									:placeholder="app.language.jbjk_IbodyTemperature" />
							</view>
						</view>
						<!-- 心率 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_heartRate }}:</text>
							<view class="formB">
								<input type="text" v-model="info.heartRate"
									:placeholder="app.language.jbjk_heartRate" />
							</view>
						</view>
						<!-- 血氧饱和度 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_bloodOxygenSaturation }}:</text>
							<view class="formB">
								<input type="text" v-model="info.bloodOxygenSaturation"
									:placeholder="app.language.jbjk_IbloodOxygenSaturation" />
							</view>
						</view>
						<!-- 高压 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_bloodPressure }}:</text>
							<view class="formB">
								<input type="text" v-model="info.bloodPressure"
									:placeholder="app.language.jbjk_IbloodPressure" />
							</view>
						</view>
						<!-- 抵压 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.jbjk_bloodPressured }}:</text>
							<view class="formB">
								<input type="text" v-model="info.dycount"
									:placeholder="app.language.jbjk_IbloodPressured" />
							</view>
						</view>
						<!-- 尿酸 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.rcjk_uricAcid }}:</text>
							<view class="formB">
								<input type="text" v-model="info.uricAcid" :placeholder="app.language.rcjk_IuricAcid" />
							</view>
						</view>
						<!-- 血糖 -->
						<view class="formItem1">
							<text><text class="bt">*</text>{{ app.language.rcjk_bloodSugar }}:</text>
							<view class="formB">
								<input type="text" v-model="info.bloodSugar"
									:placeholder="app.language.rcjk_IbloodSugar" />
							</view>
						</view>
						<!-- 其他 -->
						<view class="formItem1">
							<text>{{ app.language.rcjk_other }}:</text>
							<view class="formB">
								<input type="text" v-model="info.other" :placeholder="app.language.rcjk_Iother" />
							</view>
						</view>
						<!-- 提交 -->
						<view class="uni-btn-v">
							<button @click="submit" class="btn">提交修改</button>
							<!-- <button type="default" form-type="reset">Reset</button> -->
						</view>
					</form>
				</view>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		addRcjk
	} from '@/api/user.js'
	const global = getApp().globalData;
	export default {
		data() {
			return {
				app: {
					global: global,
					name: global.appName,
					language: global.language
				},
				// 体检时间
				time: "",
				token: "",
				hrUuid: "",
				info: {},
			}
		},
		onLoad() {
			this.time = this.app.language.qxz
			this.getToken()
		},
		methods: {
			// 获取token
			getToken() {
				let that = this
				uni.getStorage({
					key: 'loginData',
					success: function(res) {
						console.log('res', res)
						that.token = res.data.userInfo.appToken
						that.info = res.data.userInfo
					}
				});
			},

			// 体检时间选择
			bindTimeChange(e) {
				this.time = e.detail.value
				this.info.inspectionTime = e.detail.value
			},

			// 提交数据
			submit() {
				// 体检时间
				if (!this.time || this.time === this.app.language.qxz) {
					uni.showToast({
						title: this.app.language.jbjk_ijcTime,
						icon: 'none',
					});
					return
				}
				if (!this.info.bodyTemperature) {
					uni.showToast({
						title: this.app.language.jbjk_IbodyTemperature,
						icon: 'none',
					});
					return
				}
				if (!this.info.heartRate) {
					uni.showToast({
						title: this.app.language.jbjk_heartRate,
						icon: 'none',
					});
					return
				}
				if (!this.info.bloodOxygenSaturation) {
					uni.showToast({
						title: this.app.language.jbjk_IbloodOxygenSaturation,
						icon: 'none',
					});
					return
				}
				if (!this.info.dycount) {
					uni.showToast({
						title: this.app.language.jbjk_IbloodPressured,
						icon: 'none',
					});
					return
				}
				if (!this.info.bloodPressure) {
					uni.showToast({
						title: this.app.language.jbjk_IbloodPressure,
						icon: 'none',
					});
					return
				}
				if (!this.info.uricAcid) {
					uni.showToast({
						title: this.app.language.rcjk_IuricAcid,
						icon: 'none',
					});
					return
				}
				if (!this.info.bloodSugar) {
					uni.showToast({
						title: this.app.language.rcjk_IbloodSugar,
						icon: 'none',
					});
					return
				}
				uni.showLoading({
					title: this.app.language.jzz,
				});
				this.info.department = this.info.department
				this.info.appToken = this.token
				this.info.hrUuid = this.info.uuid;
				console.log('r', this.info)
				addRcjk(this.info).then((res) => {
					if (res.code == 200) {
						uni.hideLoading();
						uni.showToast({
							title: this.app.language.success,
							icon: 'success',
						});
						setTimeout(() => {
							console.log('跳转首页')
							uni.reLaunch({
								url: '/pages/user/rcHealth'
							});
						}, 1000);
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		padding: 20rpx;
	}

	.form {
		box-shadow: 1px 1px 10rpx #ddd;
		/* display: block; */
		width: 100%;
		padding-bottom: 20rpx;
	}

	.formItem {
		margin: 10rpx 0;
		padding: 10rpx;
		/* height: 162rpx; */
		position: relative;
		border-bottom: 1px dashed #ddd
	}

	.infoBox {
		border: 1px solid #ddd;
		padding: 0 20rpx;
		box-shadow: 1px 1px 10rpx #ddd;
	}

	.infoBox1 {
		border: 1px solid #ddd;
		margin-top: 20rpx;
		padding: 0 15rpx;
		box-shadow: 1px 1px 10rpx #ddd;
	}

	.formItem1 {
		margin: 10rpx 0;
		padding: 10rpx;
		/* height: 162rpx; */
		position: relative;
		border-bottom: 1px dashed #ddd
	}

	.formB {
		/* background-color: #f3f3f3; */
		font-size: 24rpx;
		padding: 10rpx;
		margin-top: 10rpx;
		position: absolute;
		right: 10rpx;
		top: -2rpx;
		text-align: right;
		color: #808080;
	}

	.formItem text,
	.formItem1 text {
		font-size: 26rpx;
	}

	.hjbImg button {
		font-size: 22rpx;
		width: 149rpx;
		height: 56rpx;
		background: #2f8ef9;
		color: #fff;
	}

	.hjbImg {
		/* position: absolute;
		bottom: 10rpx; */
		width: 150rpx;
		margin-top: 20rpx;
	}

	.scimage {
		width: 142rpx;
		height: 80rpx;
		position: absolute;
		bottom: 4rpx;
		left: 200rpx;
	}

	.title {
		margin-top: 30rpx;
		font-weight: bold;
		font-size: 28rpx;
	}

	.submit {
		background-color: #2f8ef9;
		color: #fff;
		font-size: 28rpx;
		width: 95%;
		margin: 20rpx auto 0;
	}

	.picker {
		padding: 10px;
		text-align: center;
		margin-top: -25rpx;
	}

	.bt {
		color: red;
		margin-right: 5rpx;
	}

	.btn {
		background-color: #2f8ef9;
		color: #fff;
		font-size: 28rpx;
		height: 60rpx;
		line-height: 60rpx;
		margin-top: 20rpx;
		width: 95%;
	}

	.uni-input {
		width: 262rpx;
		color: #808080;
		text-align: right !important;
	}
</style>